from django.contrib import admin

from common.common_func import *
from .models import *
from jet.admin import CompactInline


# Register your models here.


@admin.register(BasementManager)
class BasementManagerAdmin(admin.ModelAdmin):
    list_display = ['basenum', 'name', 'status']
    search_fields = ['basenum', 'name', 'status']
    actions = [make_status_enabled, make_status_disabled]

    class Media:
        js = ('/static/js/BasementManagerAdmin.js',)


@admin.register(PeopleManager)
class PeopleManagerAdmin(admin.ModelAdmin):
    list_display = ['peoplenum', 'name', 'status']
    search_fields = ['peoplenum', 'name', 'status']


@admin.register(AccountManager)
class AccountManagerAdmin(admin.ModelAdmin):
    list_display = ['account_num', 'account_name',
                    'balance_date',
                    'balanse_money', 'account_type', 'is_default']
    search_fields = ['account_num', 'account_name',
                     'is_default', 'balance_date',
                     'balanse_money', 'account_type']


class SupplierConcatorInline(CompactInline):
    model = SupplierConcator
    extra = 3
    show_change_link = True


@admin.register(Supplier)
class SupplierManagerAdmin(admin.ModelAdmin):
    list_display = ['supplier_num', 'supplier_name',
                    'supplier_catagery',
                    'balance_date', 'balanse_money', 'tax_percentange']
    search_fields = ['supplier_num', 'supplier_name',
                     'supplier_catagery',
                     'balance_date', 'balanse_money', 'tax_percentange']
    inlines = [SupplierConcatorInline]


class CustomerConcatorInline(CompactInline):
    model = CustomerConcator
    extra = 3
    show_change_link = True


@admin.register(Customer)
class CustomerAdmin(admin.ModelAdmin):
    list_display = ['customer_num', 'customer_name',
                    'customer_catagery',
                    'customer_level', 'balance_date', 'balanse_money', 'balanse_pre_money']
    search_fields = ['customer_num', 'customer_name',
                     'customer_catagery',
                     'customer_level', 'balance_date', 'balanse_money', 'balanse_pre_money']
    inlines = [CustomerConcatorInline]


class ProductPicInline(admin.StackedInline):
    model = ProductPic
    extra = 3


@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ['product_num', 'product_name', 'product_sn', 'product_spec',
                    'product_kind', 'basement', 'unit', 'has_base_alert']
    search_fields = ['product_num', 'product_name', 'product_sn', 'product_spec',
                     'product_kind', 'basement', 'unit', 'has_base_alert']

    inlines = [ProductPicInline]
